import requests
import re
import lxml.html

etree = lxml.html.etree

class ZhiCity:

    #初始化函数
    def __init__(self):
        self.header = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36',
            'Content-type': 'text/html',
            'charset': 'utf-8'}


    #获取文件信息
    def get_project(self):
        for i in range(221672,221675):

            wholeurl = "http://www.taskcity.com/projects/"+str(i)
            response = requests.get(url=wholeurl,params={"page":str(i)},headers = self.header)

            response.encoding="utf-8"
            #print("\n*************************")
            print(response.status_code)
            if response.status_code == 200:
                html = etree.HTML(response.text)
                prize = str(html.xpath("/html/body/div[1]/div/div[7]/div[1]/div[1]/div[2]/b/text()"))[20:-18]

                print(str(i) + " prize:" + prize)

                #两步走，先去除千分号，再字符串转数字
                num = re.findall(r'\d+',prize.replace(',',''))

                #print("prize:")
                #for n in num:
                #    print(str(n))

                #print("prize_len:"+str(len(num)))



                lis = html.xpath('//div[@class ="pull-left space-right-30"]//a[@style="margin-left:5px"]/text()')

                flag = 0
                #print("skills:")
                for ll in lis:
                    if len(ll) > 0:
                        flag = 1
                        print(ll)
                #print("__flag="+str(flag))

                lis = html.xpath('//div[@class ="pull-left space-right-30"]//a[@style="font-size:12px"]/text()')

                #print("type:")
                flag = 0
                for ll in lis:
                    if len(ll) > 0:
                        flag+=1
                        print(ll)
                #print("_flag="+str(flag))

                #print("+++++++++++++++++++++++++")




if __name__ in "__main__":
    cls = ZhiCity()
    cls.get_project()
